load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bzl:cpp_library.bzl", "cpp_library")
load("//bzl:cpp_unittest.bzl", "cpp_unittest")

package(default_visibility = ["//visibility:public"])

cpp_unittest(
    name = "access_test",
    srcs = ["AccessTest.cpp"],
    deps = [
        "//folly/container:access",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "array_test",
    srcs = ["ArrayTest.cpp"],
    deps = [
        "//folly/container:array",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "bit_iterator_test",
    srcs = ["BitIteratorTest.cpp"],
    deps = [
        "//folly/container:bit_iterator",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "enumerate_test",
    srcs = ["EnumerateTest.cpp"],
    deps = [
        "//folly:range",
        "//folly/container:enumerate",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "evicting_cache_map_test",
    srcs = ["EvictingCacheMapTest.cpp"],
    deps = [
        "//folly/container:evicting_cache_map",
        "//folly/portability:gtest",
    ],
)

cpp_library(
    name = "f14_test_util",
    hdrs = [
        "F14TestUtil.h",
    ],
    deps = [
        "//folly/container/detail:f14_hash_detail",
    ],
)

cpp_unittest(
    name = "f14_fwd_test",
    srcs = [
        "F14FwdTest.cpp",
    ],
    deps = [
        "//folly/container:f14_hash_fwd",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "f14_map_test",
    srcs = [
        "F14MapTest.cpp",
    ],
    deps = [
        ":f14_test_util",
        ":tracking_types",
        "//folly:benchmark",
        "//folly:conv",
        "//folly:fbstring",
        "//folly:portability",
        "//folly/container:f14_hash",
        "//folly/hash",
        "//folly/portability:gtest",
        "//folly/test:test_utils",
        "@glog",
    ],
)

cpp_unittest(
    name = "f14_map_fallback_test",
    srcs = [
        "F14MapTest.cpp",
    ],
    local_defines = ["FOLLY_F14_FORCE_FALLBACK"],
    target_compatible_with = select({
        # TODO: fails on Mac.
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        ":f14_test_util",
        ":tracking_types",
        "//folly:benchmark",
        "//folly:conv",
        "//folly:fbstring",
        "//folly:portability",
        "//folly/container:f14_hash",
        "//folly/hash",
        "//folly/portability:gtest",
        "//folly/test:test_utils",
        "@glog",
    ],
)

cpp_unittest(
    name = "f14_policy_test",
    srcs = [
        "F14PolicyTest.cpp",
    ],
    deps = [
        "//folly/container:f14_hash",
        "//folly/portability:gtest",
    ],
)

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "f14_set_test",
#     srcs = [
#         "F14SetTest.cpp",
#     ],
#     deps = [
#         ":f14_test_util",
#         ":tracking_types",
#         "//folly:benchmark",
#         "//folly:conv",
#         "//folly:fbstring",
#         "//folly:portability",
#         "//folly/container:f14_hash",
#         "//folly/lang:keep",
#         "//folly/portability:gtest",
#         "//folly/test:test_utils",
#         "@glog",
#     ],
# )

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "f14_set_fallback_test",
#     srcs = [
#         "F14SetTest.cpp",
#     ],
#     local_defines = ["FOLLY_F14_FORCE_FALLBACK=1"],
#     deps = [
#         ":f14_test_util",
#         ":tracking_types",
#         "//folly:benchmark",
#         "//folly:conv",
#         "//folly:fbstring",
#         "//folly:portability",
#         "//folly/container:f14_hash",
#         "//folly/lang:keep",
#         "//folly/portability:gtest",
#         "//folly/test:test_utils",
#         "@glog",
#     ],
# )

cpp_unittest(
    name = "heap_vector_types_test",
    srcs = ["heap_vector_types_test.cpp"],
    deps = [
        "//folly:random",
        "//folly:range",
        "//folly:small_vector",
        "//folly:sorted_vector_types",
        "//folly:utility",
        "//folly/container:heap_vector_types",
        "//folly/memory:malloc",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "f14_interprocess_test",
#     srcs = [
#         "F14InterprocessTest.cpp",
#     ],
#     linkopts = select({
#         "@platforms//os:windows": [],
#         "//conditions:default": ["-lrt"],
#     }),
#     deps = [
#         "//folly:random",
#         "//folly:traits",
#         "//folly/container:f14_hash",
#         "//folly/portability:gtest",
#         "@boost.interprocess",
#         "@fmt",
#     ],
# )

cc_binary(
    name = "f14_small_overheads",
    srcs = [
        "F14SmallOverheads.cpp",
    ],
    deps = [
        "//folly/container:f14_hash",
    ],
)

cpp_unittest(
    name = "f14_asan_support_test",
    srcs = [
        "F14AsanSupportTest.cpp",
    ],
    deps = [
        "//folly:portability",
        "//folly/container:f14_hash",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "foreach_test",
    srcs = ["ForeachTest.cpp"],
    deps = [
        "//folly/container:foreach",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "heterogeneous_access_test",
    srcs = [
        "HeterogeneousAccessTest.cpp",
    ],
    target_compatible_with = select({
        # Test relies on char_traits<int>, which isn't available on Mac.
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        "//folly:fbstring",
        "//folly:portability",
        "//folly:range",
        "//folly:small_vector",
        "//folly:traits",
        "//folly/container:heterogeneous_access",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "iterator_test",
    srcs = ["IteratorTest.cpp"],
    deps = [
        "//folly/container:iterator",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "merge_test",
    srcs = ["MergeTest.cpp"],
    deps = [
        "//folly/container:merge",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "range_traits_test",
    srcs = ["range_traits_test.cpp"],
    deps = [
        "//folly/container:range_traits",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "regex_match_cache_test",
    srcs = ["RegexMatchCacheTest.cpp"],
    deps = [
        "//folly:portability",
        "//folly:utility",
        "//folly/container:f14_hash",
        "//folly/container:regex_match_cache",
        "//folly/container:sorted_vector_types",
        "//folly/container:span",
        "//folly/lang:keep",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "@fmt",
    ],
)

cpp_unittest(
    name = "span_test",
    srcs = ["span_test.cpp"],
    target_compatible_with = select({
        # TODO: fails on Mac.
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        "//folly/container:span",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "sparse_byte_set_test",
    srcs = ["SparseByteSetTest.cpp"],
    deps = [
        "//folly/container:sparse_byte_set",
        "//folly/portability:gtest",
    ],
)

cpp_library(
    name = "tracking_types",
    hdrs = [
        "TrackingTypes.h",
    ],
    deps = [
        "//folly:function",
        "//folly/hash",
        "//folly/lang:safe_assert",
        "//folly/portability:asm",
    ],
)

# TODO(kgk): Fix test.
# cpp_unittest(
#     name = "tape_test",
#     srcs = ["tape_test.cpp"],
#     deps = [
#         "//folly:small_vector",
#         "//folly/container:tape",
#         "//folly/portability:gmock",
#         "//folly/portability:gtest",
#     ],
# )

cpp_unittest(
    name = "tape_bench",
    srcs = ["tape_bench.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly/container:tape",
        "//folly/init",
    ],
)

cpp_unittest(
    name = "util_test",
    srcs = ["UtilTest.cpp"],
    deps = [
        "//folly:optional",
        "//folly:range",
        "//folly/container/detail:util",
        "//folly/container/test:tracking_types",
        "//folly/portability:gtest",
        "@glog",
    ],
)

cpp_unittest(
    name = "weighted_evicting_cache_map_test",
    srcs = ["WeightedEvictingCacheMapTest.cpp"],
    deps = [
        "//folly/container:weighted_evicting_cache_map",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "intrusive_heap_test",
    srcs = ["IntrusiveHeapTest.cpp"],
    deps = [
        "//folly:random",
        "//folly/container:intrusive_heap",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
    ],
)

cc_binary(
    name = "hash_maps_bench",
    srcs = ["HashMapsBench.cpp"],
    target_compatible_with = select({
        # Uses functions that are not available on Mac.
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
    deps = [
        "//folly:benchmark",
        "//folly:conv",
        "//folly:format",
        "//folly:function",
        "//folly/container:f14_hash",
        "//folly/hash",
        "//folly/init",
        "//folly/portability:gflags",
        "@glog",
    ],
)

cpp_unittest(
    name = "reserve_test",
    srcs = ["ReserveTest.cpp"],
    deps = [
        "//folly/container:f14_hash",
        "//folly/container:reserve",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "fbvector_test",
    srcs = [
        "FBVectorTest.cpp",
        "FBVectorTests.cpp.h",
    ],
    deps = [
        "//folly:fbstring",
        "//folly:fbvector",
        "//folly:random",
        "//folly:traits",
        "//folly/container:foreach",
        "//folly/portability:gtest",
        "//folly/test:fbvector_test_util",
    ],
)

cpp_unittest(
    name = "map_util_test",
    srcs = ["MapUtilTest.cpp"],
    deps = [
        "//folly:map_util",
        "//folly:sorted_vector_types",
        "//folly:traits",
        "//folly/portability:gtest",
    ],
)

cpp_unittest(
    name = "small_vector_test",
    srcs = ["small_vector_test.cpp"],
    deps = [
        "//folly:conv",
        "//folly:small_vector",
        "//folly:sorted_vector_types",
        "//folly:traits",
        "//folly/container:iterator",
        "//folly/portability:gtest",
        "@boost.algorithm",
        "@fmt",
    ],
)

cpp_unittest(
    name = "sorted_vector_types_test",
    srcs = ["sorted_vector_test.cpp"],
    deps = [
        "//folly:optional",
        "//folly:range",
        "//folly:small_vector",
        "//folly:sorted_vector_types",
        "//folly:utility",
        "//folly/memory:malloc",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
    ],
)
